package org.bet.utils;

import java.util.HashMap;
import java.util.Map;


public abstract class ClassUtils extends org.springframework.util.ClassUtils {
	private static final Map<Class, Class> primitiveTypeMap = new HashMap<Class, Class>(16);


	static {
		primitiveTypeMap.put(boolean.class, Boolean.class);
		primitiveTypeMap.put(byte.class, Byte.class);
		primitiveTypeMap.put(char.class, Character.class);
		primitiveTypeMap.put(double.class, Double.class);
		primitiveTypeMap.put(float.class, Float.class);
		primitiveTypeMap.put(int.class, Integer.class);
		primitiveTypeMap.put(long.class, Long.class);
		primitiveTypeMap.put(short.class, Short.class);
	}
	
	public static Class getClassIfPossible(String className){
		try {
			
			return forName(className);
		} 
		catch (Exception e) {
			return null;
		}	
	}
	public static boolean isAssignable(Class lhsType, Class rhsType){
		boolean assignable = org.springframework.util.ClassUtils.isAssignable(lhsType, rhsType);
		
		if(!assignable && rhsType.isPrimitive()){
			assignable = lhsType.equals(primitiveTypeMap.get(rhsType));
		}
		return assignable;
	}

}
